package com.fer.tankr.controllers;

import org.andengine.engine.camera.Camera;
import org.andengine.entity.scene.menu.MenuScene;
import org.andengine.entity.scene.menu.MenuScene.IOnMenuItemClickListener;
import org.andengine.entity.scene.menu.item.IMenuItem;

import android.content.Intent;
import android.util.Log;

import com.fer.andenginemvc.api.Controller;
import com.fer.tankr.MainActivity;
import com.fer.tankr.RequestActivity;
import com.fer.tankr.scenes.MainMenuScene;
import com.fer.tankr.scenes.SceneManagerImpl;

public class MenuController extends Controller<MainActivity> implements IOnMenuItemClickListener{


	public MenuController(MainActivity baseGame, Camera camera) {
		super(new MainMenuScene(camera,baseGame.getVertexBufferObjectManager(),baseGame.assetManager),baseGame, camera);
		
		getScene().setBackgroundEnabled(true);
		getScene().setOnMenuItemClickListener(this);
	}


	@Override
	public void onShow() {
		
		camera.setChaseEntity(scene);
		if (camera.getHUD()!=null)
		{
			camera.getHUD().detachSelf();
		}
	}
	
	public MainMenuScene getScene()
	{
		return (MainMenuScene)scene;
	}
	
	@Override
	public boolean onMenuItemClicked(MenuScene pMenuScene, IMenuItem pMenuItem,
			float pMenuItemLocalX, float pMenuItemLocalY) {
		
		if (pMenuItem.getID()==MainMenuScene.ITEM_HELP)
		{
			baseGame.setScene(SceneManagerImpl.HELP);
		}
		else if(pMenuItem.getID()==MainMenuScene.ITEM_HIGH_SCORES)
		{
			baseGame.setScene(SceneManagerImpl.HIGH_SCORE);
		}
		else if(pMenuItem.getID()==MainMenuScene.ITEM_PLAY)
		{
			baseGame.setScene(SceneManagerImpl.LEVELS);
		}
		else if(pMenuItem.getID()==MainMenuScene.ITEM_REQUEST_FEATURE)
		{
			Intent intent = new Intent(baseGame, RequestActivity.class);
			baseGame.startActivity(intent);
		}
		
		return true;
	}
}







